03. Demo: Creating Historical Returns
Part 1 - Obtaining Historical Stock Prices
Cd13639 C1 L1 DEMO 1 V1
Note: The more recent version of yfinance automatically uses Adjusted Close price for the Price field, but if you want to see the same output as the one shown on the video, you may add this argument auto_adjust=False when calling the yf.download() function:
historical_prices = yf.download(tickers, start=start_date, end=end_date, auto_adjust=False)
Efficiently Retrieving Historical Stock Prices
This tutorial focuses on acquiring and analyzing historical stock prices programmatically using Python and the yfinance library.
Steps Covered:
- Objective: Research & Analysis
- Aim to gather stock prices without manual downloads for a vast number of stocks.
- Resource Utilization: Yahoo Finance
- Utilize Yahoo Finance for accessing historical stock data.
- Automated Retrieval with yfinance
- Install and set up the yfinance Python library.
- Import the library, define start and end dates, and specify stock tickers.
- Perform data download functionality via a simple code execution.
- Analyzing the S&P 500
- Extract S&P 500 stock tickers using the Pandas library.
- Filter and keep only the essential ticker information.
- Data Management and Storage
- Clean data by keeping tickers with over 100 observations.
- Save the procedure in a script to reuse and regenerate datasets efficiently for future analyses.
Emphasizes the benefits of automated processes in conducting extensive financial analyses in Python.
Demo Discussion
AI For Trading C1 L1 A05 Creating Historical Returns DEMO Part 1 V2
Data Analysis & Trading Strategy Simplification
This demonstration showcases the importance of reshaping historical price data to produce accurate return data for analysis.
Data Integrity: Ensuring no future data from beyond the analysis period is used, which prevents misleading results. An example is excluding post-announcement earnings in predictions when trading.
Testing Models: When building trading models based on forward returns, positions must be set and closed at specific times (e.g., 4:00 PM Eastern) to ensure consistency with back-tested scenarios.
Institutional Influence: Institutional investors place large trades near market close, impacting prices. It's crucial to understand and anticipate their actions when executing trades based on data analysis.
Cross-Ticker Analysis: Instead of analyzing each ticker separately, combining them provides a comprehensive view of general trends across markets, ensuring a solid basis for AI model developments.
The approach allows for detecting overarching trends, crucial for forming robust, unbiased trading strategies within real-world constraints.